{% load i18n %}
{% load materializecss %}
{% load utils %}

{% if field|is_checkbox %}
  <div class="input input-field col {{ classes.label }}">
    <div class="{{ classes.single_value }}">
      <p>
        {% if field.auto_id %}
          <input id="{{ field.auto_id }}" name="{{ field.name }}" class="filled-in" type="checkbox"{% if field.value %} checked="checked" {% endif %}>
          <label for="{{ field.auto_id }}">
            {{ field.label }}
          </label>
        {% endif %}
        {% for error in field.errors %}
          <p class="help-block materialize-red-text">{{ error }}</p>
        {% endfor %}
        {% if field.help_text %}
          <p class="help-block">
            {{ field.help_text|safe }}
          </p>
        {% endif %}
      </p>
    </div>
  </div>
{% elif field|is_multiple_checkbox %}
  <div class="input input-field col {{ classes.label }}">
    {% if field.auto_id %}
      <label class="control-label {{ classes.label }}">
        {{ field.label }}
        {% if not field.field.required %}
          {% trans "(optional)" context "Dashboard form labels" %}
        {% endif %}
      </label>
    {% endif %}
    {% for choice in field %}
      <p>
        <input id="{{ choice.id_for_label }}" name="{{ choice.name }}" class="filled-in" type="checkbox" value="{{ choice.choice_value }}" {% if choice.choice_value in choice.value %} checked="checked" {% endif %}>
        <label for="{{ choice.id_for_label }}">
          {{ choice.choice_label }}
        </label>
      </p>
    {% endfor %}
    {% for error in field.errors %}
      <p class="help-block materialize-red-text">
        {{ error }}
      </p>
    {% endfor %}
    {% if field.help_text %}
      <p class="help-block">
        {{ field.help_text|safe }}
      </p>
    {% endif %}
  </div>
{% elif field|is_radio %}
  <div class="input input-field col {{ classes.label }}">
    {% if field.auto_id %}
      <label class="control-label {{ classes.label }}">
        {{ field.label }}{% if not field.field.required %} {% trans "(optional)" context "Dashboard form labels" %}{% endif %}
      </label>
    {% endif %}
    {% for choice in field %}
      <p>
        {{ choice.tag }}
        <label for="{{ choice.id_for_label }}">
          {{ choice.choice_label }}
        </label>
      </p>
    {% endfor %}
    {% for error in field.errors %}
      <p class="help-block materialize-red-text">
        {{ error }}
      </p>
    {% endfor %}
    {% if field.help_text %}
      <p class="help-block">
        {{ field.help_text|safe }}
      </p>
    {% endif %}
  </div>
{% elif field|is_date_input %}
    <div class="input input-field col {{ classes.label }}">
      <label class="active" for="{{ field.auto_id }}">
        {{ field.label }}
        {% if not field.field.required %}
          {% trans "(optional)" context "Dashboard form labels" %}
        {% endif %}
      </label>
      <input type="date" id="{{ field.auto_id }}" class="datepicker" name="{{ field.name }}"
        value="{% if field.value %}{{ field.value|date:"Y-m-d" }}{% endif %}" data-value="{% if field.value %}{{ field.value|date:"Y-m-d" }}{% endif %}">
      {% for error in field.errors %}
        <p class="help-block materialize-red-text">
          {{ error }}
        </p>
      {% endfor %}
      {% if field.help_text %}
        <p class="help-block">
          {{ field.help_text|safe }}
        </p>
      {% endif %}
    </div>
{% elif field|is_select %}
  <div class="input input-field col {{ classes.label }}">
    {% if field|is_checkbox_select_multiple %}
      {% if field.auto_id %}
        <label class="control-label {{ classes.label }}">
          {{ field.label }}
          {% if not field.field.required %}
            {% trans "(optional)" context "Dashboard form labels" %}
          {% endif %}
        </label>
      {% endif %}
      <div class="{{ classes.value }}">
        {% for choice in field %}
          <p>
            {{ choice.tag }}
            <label for="{{ choice.id_for_label }}">
              {{ choice.choice_label }}
            </label>
          </p>
        {% endfor %}
        {% for error in field.errors %}
          <p class="help-block materialize-red-text">
            {{ error }}
          </p>
        {% endfor %}
        {% if field.help_text %}
          <p class="help-block">
            {{ field.help_text|safe }}
          </p>
        {% endif %}
      </div>
    {% else %}
      <label for="{{ field.id_for_label }}">
        {{ field.label }}{% if not field.field.required %} {% trans "(optional)" context "Dashboard form labels" %}{% endif %}
      </label>
      {{ field }}
      {% for error in field.errors %}
        <p class="help-block materialize-red-text">
          {{ error }}
        </p>
      {% endfor %}
      {% if field.help_text %}
        <p class="help-block">
          {{ field.help_text|safe }}
        </p>
      {% endif %}
    {% endif %}
  </div>
{% elif field|is_textarea %}
  <div class="input input-field col {{ classes.label }}">
    <textarea id="{{ field.auto_id }}" class="materialize-textarea {{ field.field.widget.attrs.class }}"
    name="{{ field.name }}">
      {% if field.value %}
        {{ field.value }}
      {% endif %}
    </textarea>
    {% if field.auto_id %}
      <label class="active {{ classes.label }}" for="{{ field.auto_id }}">
        {{ field.label }}
        {% if not field.field.required %}
          {% trans "(optional)" context "Dashboard form labels" %}
        {% endif %}
      </label>
      {% endif %}
      {% for error in field.errors %}
        <p class="help-block materialize-red-text">{{ error }}</p>
      {% endfor %}
      {% if field.help_text %}
        <p class="help-block">
          {{ field.help_text|safe }}
        </p>
      {% endif %}
  </div>

{% elif field|is_file %}
  <div class="input col {{ classes.label }}">
    <p>
      {% if field.auto_id %}
        <label class="{{ classes.label }}" for="{{ field.auto_id }}">
          {{ field.label }}
          {% if not field.field.required %}
            {% trans "(optional)" context "Dashboard form labels" %}
          {% endif %}
        </label>
        <br>
      {% endif %}
      {{ field }}
    </p>
  </div>
{% elif field|is_versatile_image_ppoi_click_widget %}
  <div class="input col file-field input-field {{ classes.label }}">
    {% if field.auto_id %}
      <label class="{{ classes.label }}" for="{{ field.auto_id }}">
        {{ field.label }}
        {% if not field.field.required %}
          {% trans "(optional)" context "Dashboard form labels" %}
        {% endif %}
      </label>
    {% endif %}
      <div class="btn">
        <span>
          {% trans "File" %}
        </span>
        <input class="file-chooser" id="{{ field.auto_id }}_0"
        name="{{ field.name }}_0" type="file">
        <input class="ppoi-input" id="{{ field.auto_id }}_1"
        name="{{ field.name }}_1" type="hidden">
      </div>
      <div class="file-path-wrapper">
        <input class="file-path" type="text">
      </div>
      {% for error in field.errors %}
        <p class="help-block materialize-red-text">
          {{ error }}
        </p>
      {% endfor %}
    {% if field.help_text %}
      <p class="help-block">
        {{ field.help_text|safe }}
      </p>
    {% endif %}
  </div>
{% else %}
  <div class="input input-field col {{ classes.label }}">
    {% if field.auto_id %}
      <label class="active" for="{{ field.auto_id }}">
        {{ field.label }}
        {% if not field.field.required %}
          {% trans "(optional)" context "Dashboard form labels" %}
        {% endif %}
      </label>
    {% endif %}
    {{ field }}
    {% for error in field.errors %}
      <p class="help-block materialize-red-text">{{ error }}</p>
    {% endfor %}
    {% if field.help_text %}
      <p class="help-block">
        {{ field.help_text|safe }}
      </p>
    {% endif %}
  </div>
{% endif %}
